package com.example.exam.controller;

import com.example.exam.entity.Role;
import com.example.exam.entity.Teacher;
import com.example.exam.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * (Teacher)表控制层
 *
 * @author makejava
 * @since 2021-09-04 15:02:45
 */
@RestController
@RequestMapping("teacher")
public class TeacherController {
    /**
     * 服务对象
     */
    @Autowired
    private TeacherService teacherService;

    /**
     * 通过主键查询单条数据
     *
     * @param
     * @return 单条数据
     */
    @RequestMapping("/selectOne")
    public Teacher selectOne(HttpSession session) {
        Integer id = (Integer) session.getAttribute("userId");
        return this.teacherService.queryById(id);
    }

    @RequestMapping("/updateOne")
    public Teacher updateOne(Teacher teacher, HttpSession session) {
        Teacher teacher1 = teacherService.queryById((int)session.getAttribute("userId"));
        if (teacher.getTecname() != null) {
            teacher1.setTecname(teacher.getTecname());
        }
        if (teacher.getInstitute() != null) {
            teacher1.setInstitute(teacher.getInstitute());
        }
        if (teacher.getEmail() != null) {
            teacher1.setEmail(teacher.getEmail());
        }
        if (teacher.getTel() != null) {
            teacher1.setTel(teacher.getTel());
        }
        return this.teacherService.update(teacher1);
    }
}